-
-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New "add-lines" configurator for simple file patching + importmap support #975
Conversation
528664b
to
1d1e0f9
Compare
This is ready for review 🖖 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks OK to me. Thanks Ryan (and Kevin)!
if (file_exists($this->rootDir.'/importmap.php')) { | ||
$this->synchronizeForAssetMapper($phpPackages); | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we configure also package.json in case both exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good question - e.g. "if package.json
exists, why not update it?". But one use-case will be that someone is using AssetMapper but has a small package.json file so that they can process Tailwind files or React files. In that case, we wouldn't want to update their package.json
. So my thinking currently is: there's a boolean choice between Encore vs AssetMapper / importmap.php
vs package.json
.
$fileContents = implode("\n", $lines); | ||
|
||
if (!$targetFound) { | ||
// TODO warn? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
display a message? Could not add lines after "%s" as no such string was found in "%s": $the-lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Do we need a rule to replace a line by another?
Thank you! I didn't NEED the replace yet, so I skipped it - it could be a |
throw new \InvalidArgumentException(sprintf('The "file" key is required for the "add-lines" configurator for recipe "%s".', $recipe->getName())); | ||
} | ||
|
||
if (isset($patch['requires']) && !$this->isPackageInstalled($patch['requires'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a string only or should we support a list of package names ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My gut is: let's keep it simple as a string for now. We could expand it later to an array if needed - I can't think of a use-case yet.
But I CAN add it now if we want it - I've been trying to focus the scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turning it into an array later would require using a different key, to avoid making recipes incompatible with older versions of Flex that would break badly when receiving something else than a string. So if we don't support an array already, we should at least properly handled unsupported values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I've added support for an array, as it turned out to be just as easy as checking for the type and throwing an exception.
…ryan) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Adding Asset Mapper support + new StimulusBundle | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Tickets | None | License | MIT Adds: * A) Integration with new `symfony.importmap` key introduced to Flex in symfony/flex#975 * B) An "asset mapper" path in each bundle so that you can refer to the controller/files in that bundle. * C) Introduces new StimulusBundle (thanks to `@jmsche` for helping port from WebpackEncoreBundle). This includes the Twig `stimulus_*` functions + a revamped "helper" system for generating those attributes. * D) The new StimulusBundle also contains integration for AssetMapper to load custom controllers and `controllers.json`. Cheers! Commits ------- b8acf1a Adding Asset Mapper support + new StimulusBundle
} | ||
|
||
if (!isset($patch['content'])) { | ||
throw new \InvalidArgumentException(sprintf('The "value" key is required for the "add-lines" configurator for recipe "%s".', $recipe->getName())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we throw or should we ignore the invalid recipe ? throwing would break the whole composer command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All those validation rules should be implemented as part of the recipe validator for the CI of the recipes repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I've made a PR to add the linting rules - symfony-tools/recipes-checker#14
I've also relaxed these to low-priority warnings (and skipping the rule). It will also help if we add more capabilities in the future to recipes, but they are perhaps on an older flex version (it won't work correctly, but no explosion).
…erryan) This PR was merged into the 2.x branch. Discussion ---------- Adding %PACKAGE% placeholder + fixing translations | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | None | License | MIT Tracking with Flex updates at symfony/flex#975 Commits ------- 9d21d3a Adding %PACKAGE% placeholder + fixing translations
… (weaverryan) This PR was merged into the 6.3 branch. Discussion ---------- [AssetMapper] Add "=alias" syntax to importmap:require | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | yes-ish | Deprecations? | no | Tickets | None | License | MIT | Doc PR | Still TODO I'm doing final testing against all of the UX packages. There is one edge-case where we need to require a specific package path - `vue/dist/vue.esm-bundler.js` - but alias it (i.e. make its key) set to something else - `vue` - in `importmap.php`. We need the command to support this so that symfony/flex#975 can use it when installing UX packages. Hopefully the last thing I come across - I've done a LOT of testing at this point. Thanks! Commits ------- 27ecdb4 [AssetMapper] Adding an "alias" syntax to importmap:require
…ny/asset-mapper Co-authored-by: Ryan Weaver <ryan@symfonycasts.com>
d37956c
to
0b70eb3
Compare
Thank you @weaverryan. |
…ryan) This PR was squashed before being merged into the main branch. Discussion ---------- Adding linting for the new add-lines configurator Supports symfony/flex#975 Commits ------- 89b84e9 Adding linting for the new add-lines configurator
…ryan) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Adding Asset Mapper support + new StimulusBundle | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Tickets | None | License | MIT Adds: * A) Integration with new `symfony.importmap` key introduced to Flex in symfony/flex#975 * B) An "asset mapper" path in each bundle so that you can refer to the controller/files in that bundle. * C) Introduces new StimulusBundle (thanks to `@jmsche` for helping port from WebpackEncoreBundle). This includes the Twig `stimulus_*` functions + a revamped "helper" system for generating those attributes. * D) The new StimulusBundle also contains integration for AssetMapper to load custom controllers and `controllers.json`. Cheers! Commits ------- b8acf1a2 Adding Asset Mapper support + new StimulusBundle
…erryan) This PR was merged into the 2.x branch. Discussion ---------- Adding %PACKAGE% placeholder + fixing translations | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | None | License | MIT Tracking with Flex updates at symfony/flex#975 Commits ------- 9d21d3a3 Adding %PACKAGE% placeholder + fixing translations
Hi!
Today, WebpackEncoreBundle's recipe contains the UX/Stimulus files. Soon, I will introduce a new StimulusBundle - https://github.com/weaverryan/stimulus-bundle - so that the WebpackEncoreBundle can be used without Stimulus and (more importantly) the
stimulus_()
functions can be used with AssetMapper (i.e. without Encore).This makes the recipe setup more... interesting :). This PR adds 2 things:
importmap support in
JsonSynchronizer
JsonSynchronizer
now has 2 modes, based on the presence/absence of theimportmap.php
file. If that file is present, then:A) A new symfony.importmap config is read from the bundle's
package.json
file and these are added to theimportmap.php
file by running thebin/console importmap:require
command. Thepath:
prefix is used to refer to a "local" file in the bundle. Sometimes the importmap entries will be different than what's needed forpackage.json
, hence having both configs.B) The
controllers.json
file is updated like normalAlso, a new symfony.needsPackageAsADependency config key was added specifically for StimulusBundle. If
true
, nofile:/vendor/...
package will be added topackage.json
when using Encore.add-lines Configurator
The new
add-lines
configurator is able to add entire lines to thetop
,bottom
ofafter_target
of existing files (if they exist). Example usage:There is also a
requires
key to only run if another package is installed. This is needed because StimulusBundle will need a different assets/bootstrap.js based on if Encore vs AssetMapper is installedCheers!